package com.ecfront.test.dao;

import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import com.ecfront.dao.GoodsImplDAO;
import com.ecfront.pojo.Goods;
import com.ecfront.pojo.GoodsComplain;
import com.ecfront.pojo.GoodsImpl;
import com.ecfront.pojo.Message;
import com.ecfront.pojo.Shop;
import com.ecfront.pojo.ShopGoodsSort;
import junit.framework.TestCase;

public class testGoodsImpl extends TestCase {
	private static final GoodsImplDAO goodsImplDao = (GoodsImplDAO)SpringUtilTest.getBean("GoodsImplDAO");
	//save or update test
	public void testSaveOrUpdate(){
		GoodsImpl gi = new GoodsImpl();
		//gi.setId(1);
		gi.setHits(0);
		gi.setPrice(1200.0);
		gi.setInfo("修改后的商品介绍");
		gi.setDate(new Date());
		
		Goods goods = new Goods();
		goods.setId(1);
		gi.setGood(goods);
		
		Shop shop = new Shop();
		shop.setId(1);
		gi.setShop(shop);
		
		ShopGoodsSort sgs = new ShopGoodsSort();
		sgs.setId(1);
		gi.setSgs(sgs);
		
		goodsImplDao.save(gi);
	}
	//findall test
	public void testFindAll(){
		List list = goodsImplDao.findAll();
		for(Iterator iter = list.iterator();iter.hasNext();){
			GoodsImpl gi = (GoodsImpl)iter.next();
			System.out.println(gi.getInfo());
			
			System.out.println(gi.getSgs().getName());
		}
	}
	//findById test
	public void testFindById(){
		GoodsImpl gi = goodsImplDao.findById(1);
		System.out.println(gi.getId());
		System.out.println(gi.getGood().getName());
		System.out.println(gi.getShop().getName());
		System.out.println(gi.getSgs().getName());
		Set gcs = gi.getGoodsComplains();
		for(Iterator iter = gcs.iterator();iter.hasNext();){
			GoodsComplain gc = (GoodsComplain)iter.next();
			System.out.println(gc.getContent());
		}
		Set messages = gi.getMessages();
		for(Iterator iter = messages.iterator();iter.hasNext();){
			Message message = (Message)iter.next();
			System.out.println(message.getContent());
		}
	}
	//delete test
	public void testDel(){
		GoodsImpl gi = new GoodsImpl();
		gi.setId(2);
		
		goodsImplDao.delete(gi);
	}
	//property test
	public void testProperty(){
		List list = goodsImplDao.findByGiHit(0);
		for(Iterator iter = list.iterator();iter.hasNext();){
			GoodsImpl gi = (GoodsImpl)iter.next();
			System.out.println(gi.getInfo());
			System.out.println(gi.getGood().getName());
			System.out.println(gi.getShop().getName());
			System.out.println(gi.getSgs().getName());
			System.out.println(gi.getGood().getGb().getName());
			System.out.println(gi.getGood().getGs().getName());
		}
	}
}
